﻿using EFModel;
using IServices;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    [Obsolete]
    public class Teconfig_public_char: Iconfig_public_char
    {
        private readonly MyDBContext he;

        public Teconfig_public_char(MyDBContext he)
        {
            this.he = he;
        }

        Task<ResultInfo> Iconfig_public_char.Index9(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.config_public_char;
                var list = he.config_public_char
                    .Select(e => new { e.pbc_id, e.attribute_kind, e.attribute_name })
                    .OrderBy(q => q.pbc_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }

        Task<string> Iconfig_public_char.Index6(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var io = he.config_public_char.Select(s => new { s.attribute_kind, s.attribute_name, s.pbc_id })
             .Where(e => e.attribute_kind == "职称")
             .OrderBy(d => d.pbc_id).Skip((currentPage - 1) * pageSize).Take(pageSize);
                var io1 = he.config_public_char
                    .Where(e => e.attribute_kind == "职称");
                int cont = io1.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = io,
                    Message = "获取数据成功",
                    Status = 200,
                    Row = cont
                };
                return JsonConvert.SerializeObject(result);
            });
        }

        Task<int> Iconfig_public_char.delt3(int pbc_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_public_char]
                            where [pbc_id]={pbc_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<string> Iconfig_public_char.Index0(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var io = he.config_public_char.Select(s => new { s.attribute_kind, s.attribute_name, s.pbc_id })
             .Where(e => e.attribute_kind == "薪酬设置")
             .OrderBy(d => d.pbc_id).Skip((currentPage - 1) * pageSize).Take(pageSize);
                var io1 = he.config_public_char
                    .Where(e => e.attribute_kind == "薪酬设置");
                int cont = io1.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = io,
                    Message = "获取数据成功",
                    Status = 200,
                    Row = cont
                };
                return JsonConvert.SerializeObject(result);
            });
        }

        Task<int> Iconfig_public_char.Inser7(string attribute_name)
        {
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_public_char]([attribute_kind], [attribute_name])
                            values('薪酬设置','{attribute_name}');";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_public_char.delt7(int pbc_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_public_char]
                            where [pbc_id]={pbc_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_public_char.Inser6(string attribute_kind, string attribute_name)
        {
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_public_char]([attribute_kind], [attribute_name])
                            values('{attribute_kind}','{attribute_name}');";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_public_char.delt6(int pbc_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_public_char]
                            where [pbc_id]={pbc_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        public Task<string> Lexing()
        {
            return Task.Run(() => {
                return JsonConvert.SerializeObject(he.config_public_char.Where(e => e.attribute_kind == "薪酬设置").ToList());
            });
        }
    }
}
